/**
 * Author@ Cheng Feitian
 * Date: 2020-3-18
 * Description: 
 */

#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;
const int maxn = 1024;

struct Hero
{
    string name;
    int age;
    string gender;
};

void bubbleSort(struct Hero *heroesArray, int len)
{
    // 按照年龄升序排序
    for (int i = 0; i < len; i++)
    {
        for (int j = len - 1; j > i; j--)
        {
            if (heroesArray[j].age < heroesArray[i].age)
            {
                struct Hero temp;
                temp = heroesArray[i];
                heroesArray[i] = heroesArray[j];
                heroesArray[j] = temp;
            }
        }
    }
}

void printToScreen(const struct Hero *heroesArray, int len)
{
    for (int i = 0; i < len; i++)
    {
        cout << "Hero's name  :" << heroesArray[i].name << endl
             << "Hero's age   :" << heroesArray[i].age << endl
             << "Hero's gender:" << heroesArray[i].gender << endl;
    }
}

int main()
{
#ifdef LOCAL
    freopen("./result/1.in", "r", stdin);
    freopen("./result/1.out", "w", stdout);
#endif

    struct Hero heroesArray[5] =
        {{"刘备", 23, "男"},
         {"关羽", 22, "男"},
         {"张飞", 20, "男"},
         {"赵云", 21, "男"},
         {"貂蝉", 19, "女"}};
    int len = sizeof(heroesArray) / sizeof(heroesArray[0]);

    bubbleSort(heroesArray, len);
    printToScreen(heroesArray, len);

/*     {
        for (int i = 0; i < len; i++)
        {
            cout << "Hero's name  :" << heroesArray[i].name << endl
                 << "Hero's age   :" << heroesArray[i].age << endl
                 << "Hero's gender:" << heroesArray[i].gender << endl;
        }
    } */

    return 0;
}
